//
// Created by 谢哲 on 2021/4/22.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    vector<vector<double>> vdata;

    for (int i=0; i<n; ++i) {
        vector<double> cur_data(3, 0.0);
        cin >> cur_data[0] >> cur_data[1] >> cur_data[2];

        vdata.emplace_back(cur_data);
    }

    sort(vdata.begin(), vdata.end(), [](const vector<double>& a, const vector<double>& b){
        return a[2]<b[2];
    });

    double result = 0.0;
    for (int i=1; i<n; ++i) {
        result += sqrt(pow(vdata[i][0]-vdata[i-1][0], 2)
                +pow(vdata[i][1]-vdata[i-1][1], 2)
                +pow(vdata[i][2]-vdata[i-1][2], 2));
    }

    cout << fixed << setprecision(3) << result;

    return 0;
}